package com.maker.mcp.server.tool;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

@Component
@Slf4j
public class DateTool {



    @Tool(description = "获取当前时间")
    public String getCurrentDate(){
        log.info("=============调用MCP工具：getCurrentDate=============");
        String  currentTime = String.format("当前的时间是%s", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        return currentTime;
    }




    @Tool(description = "根据城市所在的时区id来获取当前时间")
    public String getCurrentDateByZoneId(String cityName,String zoneId){
        log.info("=============调用MCP工具：getCurrentDateByZoneId=============");
        log.info(String.format("根据城市所在的时区id来获取当前时间,城市名称:%s,时区id:%s",cityName,zoneId));
        ZoneId zone = ZoneId.of(zoneId);
        //获取该时区对应的当前时间
        ZonedDateTime zonedDateTime = ZonedDateTime.now(zone);
        String  currentTime = String.format("当前的时间是%s", zonedDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        return currentTime;
    }
}
